package com.trade.dao.impl;

import java.util.Collections;
import java.util.List;

import com.trade.common.dao.impl.GenericDao;
import com.trade.dao.ISupplierDao;
import com.trade.exception.PersistenceException;
import com.trade.model.Supplier;

/**
 * 
 * @author Lin Yang
 * 
 */
public class SupplierDao extends GenericDao<Supplier, Long> implements ISupplierDao {

    @Override
    public List<Supplier> findAllLike(String name) throws PersistenceException {
        try {
            List<Supplier> suppliers = find("from Supplier where type=0 and name like ?", "%" + name + "%");

            if (suppliers == null || suppliers.size() == 0) {
                return Collections.emptyList();
            }

            return suppliers;
        } catch (Exception e) {
            throw new PersistenceException("查询供应商档案失败", e);
        }
    }
}
